package com.cea.papyrustest.uml.createcommand;

import java.util.List;

import org.eclipse.uml2.uml.Comment;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test Class for {@link Comment} creation command
 * @author Remi Schnekenburger
 */
public class CommentCreateCommandTest extends PapyrusCommandTest {

	/**
	 * Default constructor
	 * @param name name of the test case
	 */
	public CommentCreateCommandTest(String name) {
		super(name);	
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Comment.class,model);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void testExecute() {
		stack.execute(papyrusCommand);
		List<Comment> comments = model.getOwnedComments();
		assertNotNull("the comment is not created", comments);
		assertEquals("There should be one comment in this list", 1, comments.size());
		assertTrue("this is not a comment", (comments.get(0) instanceof Comment));
		
		// undo
		stack.undo();
		comments = model.getOwnedComments();
		assertNotNull("the comment is not deleted", comments);
		assertEquals("There should be no comments in this list", 0, comments.size());
		
		// redo
		stack.redo();
		comments = model.getOwnedComments();
		assertNotNull("the comment is not created", comments);
		assertEquals("There should be one comment in this list", 1, comments.size());
		assertTrue("this is not a comment", (comments.get(0) instanceof Comment));
	}
}
